package com.macro.mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dao.PmsProductAttributeCategoryDao;
import com.macro.mall.dto.PmsProductAttributeSetItem;
import com.macro.mall.dao.pms.PmsProductAttributeSetMapper;
import com.macro.mall.model.pms.PmsProductAttributeSetDO;
import com.macro.mall.model.pms.PmsProductAttributeCategoryQuery;
import com.macro.mall.service.PmsProductAttributeSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品属性分类管理Service实现类
 * Created by macro on 2018/4/26.
 */
@Service
public class PmsProductAttributeSetServiceImpl extends ServiceImpl<PmsProductAttributeSetMapper, PmsProductAttributeSetDO> implements PmsProductAttributeSetService {
    @Autowired
    private PmsProductAttributeSetMapper productAttributeCategoryMapper;
    @Autowired
    private PmsProductAttributeCategoryDao productAttributeCategoryDao;


    @Override
    public int create(String name) {
        PmsProductAttributeSetDO productAttributeCategory = new PmsProductAttributeSetDO();
        productAttributeCategory.setName(name);
        return productAttributeCategoryMapper.insertSelective(productAttributeCategory);
    }

    @Override
    public int update(Long id, String name) {
        PmsProductAttributeSetDO productAttributeCategory = new PmsProductAttributeSetDO();
        productAttributeCategory.setName(name);
        productAttributeCategory.setId(id);
        return productAttributeCategoryMapper.updateByPrimaryKeySelective(productAttributeCategory);
    }

    @Override
    public int delete(Long id) {
        return productAttributeCategoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PmsProductAttributeSetDO getItem(Long id) {
        return productAttributeCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PmsProductAttributeSetDO> getList(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        return productAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryQuery());
    }

    @Override
    public List<PmsProductAttributeSetItem> getListWithAttr() {
        return productAttributeCategoryDao.getListWithAttr();
    }
}
